﻿@{
    ViewData["Title"] = "添加PLC连接配置";
    Layout = "_Edit";
}
<article class="page-container">
    <form action="" method="post" class="form form-horizontal" id="form-add">
        <input type="hidden" class="input-text" value="@Model.ID" id="id" name="id">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>IP：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="@Model.IP" placeholder="" id="ip" name="ip">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>CPU类型：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box">
                    <select class="select" size="1" name="cpuType" id="cpuType">
                        @*<option value="">--请选择--</option>*@
                        @foreach (var item in Model.S7CpuTypes)
                        {
                            if (Model.PlcCpuType == item.CpuTypeValue)
                            {
                                <option value="@item.CpuTypeValue" selected>@item.CpuTypeName</option>
                            }
                            else
                            {
                                <option value="@item.CpuTypeValue">@item.CpuTypeName</option>
                            }
                        }
                    </select>
                </span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>支架：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="@Model.Rack" placeholder="" id="rack" name="rack">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>插槽：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="@Model.Slot" placeholder="" id="slot" name="slot">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>是否是堆垛机：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box">
                    <select class="select" size="1" name="isSc" id="isSc">
                        @*<option value="">--请选择--</option>*@
                        @foreach (var item in Model.IsScItems)
                        {
                            var tIs = 1;
                            if (!Model.IsSc)
                            {
                                tIs = 0;
                            }
                            if (Model.ID == 0)
                            {
                                tIs = -1;
                            }
                            if (tIs + "" == item.IsScValue + "")
                            {
                                <option value="@item.IsScValue" selected>@item.IsScName</option>
                            }
                            else
                            {
                                <option value="@item.IsScValue">@item.IsScName</option>
                            }
                        }
                    </select>
                </span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>堆垛机编号：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="@Model.ScEquipmentCode" placeholder="" id="scCode" name="scCode">
            </div>
        </div>
        
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" type="button" onclick="operate()" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>

@section javascript{

<script>
    $('.skin-minimal input').iCheck({
         checkboxClass: 'icheckbox-blue',
         radioClass: 'iradio-blue',
         increaseArea: '20%'
     });
     function operate(){
         var ip=$("#ip").val();
         if(ip==null||ip=="")
         {
            popupAlert('请输入IP',2,function(data){layer.close(data);});
           return;
         }
         var cpuType=$("#cpuType").val();
         if(cpuType==null||cpuType==""||cpuType==-1)
         {
            popupAlert('请选择CPU类型',2,function(data){layer.close(data);});
           return;
         }
         
         var slot=$("#slot").val();
         if(slot==null||slot=="")
         {
            popupAlert('请输入插槽数',2,function(data){layer.close(data);});
           return;
         }
         var rack=$("#rack").val();
         if(rack==null||rack=="")
         {
            popupAlert('请输入支架数',2,function(data){layer.close(data);});
           return;
         }
         var isSc=$("#isSc").val();
         if(isSc==null||isSc==""||isSc==-1)
         {
            popupAlert('请选择是否堆垛机',2,function(data){layer.close(data);});
           return;
         }
         var scCode=$("#scCode").val();
         if((scCode==null||scCode=="") && isSc == 1)
         {
            popupAlert('请输入堆垛机编码',2,function(data){layer.close(data);});
           return;
         }
        SubmitFormForAjax("/plcconnectioninfo/operateplcconnectinfo", $("#form-add").serialize(), function (data) {
            if (data.result) {
                    popupAlert('提交成功',1,function(){closePageLayer(true);});
            }else{
                popupAlert(data.message,2,function(data){layer.close(data);});
            }
        },true);
     }
</script>
}